//
//  ZLAssetCollectionExtension.swift
//  ZLExtension
//
//  Created by 赵振磊 on 2025/1/20.
//

import Photos

public extension PHAssetCollection {
    func zl_save(image: UIImage, completion: @escaping (Bool, Error?) -> Void) {
        PHPhotoLibrary.shared().performChanges({
            let creationRequest = PHAssetChangeRequest.creationRequestForAsset(from: image)
            if let assetPlaceholder = creationRequest.placeholderForCreatedAsset {
                if let albumChangeRequest = PHAssetCollectionChangeRequest(for: self) {
                    albumChangeRequest.addAssets([assetPlaceholder] as NSArray)
                }
            }
        }) { success, error in
            completion(success, error)
        }
    }
}

